//
//  MonthDestinationViewController.m
//  AndCampus
//
//  Created by 史宵宵 on 2017/12/27.
//  Copyright © 2017年 史宵宵. All rights reserved.
//

#import "MonthDestinationViewController.h"
#import "GLLimitDatePickView.h"
#import "SetMonthDestinationViewController.h"

@interface MonthDestinationViewController ()
@property(nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation MonthDestinationViewController
- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray=[NSMutableArray array];
    }
    return _dataArray;
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return UIStatusBarStyleLightContent;
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    //    [Global setStatusBarBackgroundColor:[UIColor clearColor]];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"月目标月总结";
//    self.navigationItem.rightBarButtonItem = [UIBarButtonItem rightBarButtonItemWithTitle:@"写目标" target:self selector:@selector(writeDestination)];
    [self creatdata];
}
- (void)creatdata{
    YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:[Global getUserTokenInfo] forKey:@"token"]; //用户的token
    [dic setValue:@"1" forKey:@"page"];   //页数 默认1
    [dic setValue:KREFRESHROWS forKey:@"rows"];   //每页数量
    [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppSummaryGetUserGoalsList] andParmas:dic andComplition:^(id response, BOOL isuccess) {
        if (isuccess) {
            [self.dataArray removeAllObjects];
            
            [self.dataArray addObjectsFromArray:response];
            [self.tableView reloadData];
        }
    }];
}
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.dataArray[section][@"data"] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1
                                      reuseIdentifier: CellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
     NSDictionary *dic = [[NSDictionary alloc]initWithDictionary:self.dataArray[indexPath.section][@"data"][indexPath.row]];
    cell.textLabel.text = [NSString stringWithFormat:@"%@月      %@", dic[@"mouth"], dic[@"context"]];

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 44;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = [[NSDictionary alloc]initWithDictionary:self.dataArray[indexPath.section][@"data"][indexPath.row]];
    
    SetMonthDestinationViewController *setMonthDestinationVC = [[SetMonthDestinationViewController alloc]init];
    setMonthDestinationVC.monthDesDic = dic;
    setMonthDestinationVC.year = self.dataArray[indexPath.section][@"year"];
    __weak typeof (self)unself = self;
    setMonthDestinationVC.sendMonthDestinationBlock=^(){
        [unself creatdata];
    };
    [self.navigationController pushViewController:setMonthDestinationVC animated:YES];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, kScreenW, 44);
    view.backgroundColor = KBACKGROUNDCOLOR;
    
    UILabel *label = [[UILabel alloc]init];
    label.frame = CGRectMake(15, 12, 100, 20);
    label.font = [UIFont systemFontOfSize:18];
    label.text = [NSString stringWithFormat:@"%@年",self.dataArray[section][@"year"]];
    [view addSubview:label];
    
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 44.01f;
}
/*#pragma mark - 写目标
- (void)writeDestination{
    GLLimitDatePickView *limitview=[[GLLimitDatePickView alloc]initDatePackerWithResponse:^(NSString *title) {
        
        SetMonthDestinationViewController *setMonthDestinationVC = [[SetMonthDestinationViewController alloc]init];
//        setMonthDestinationVC.resultInputType = @"newInput";
//        setMonthDestinationVC.yearStr = [title substringToIndex:4];
//        setMonthDestinationVC.monthStr = [title substringFromIndex:5];
//        setMonthDestinationVC.resultInputSuccessBlock = ^(){
//            [self creatdata];
//        };
        [self.navigationController pushViewController:setMonthDestinationVC animated:YES];

    }];
    [limitview show];
}*/
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
